#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
#include<string>
#include<map>
using namespace std;

class Solution {
public:
    vector<int> findSubstring(string s, vector<string>& words) {
        size_t len = words[0].size();
        int n = words.size();
        vector<int> ret;
        for (int i = 0; i < len; i++)
        {
            map<string, int> hashwords;
            for (auto& s : words)
                hashwords[s]++;
            for (int left = i, right = i, count = 0; right < s.size(); right += len)
            {
                if ((right - left) / len >= n)
                {
                    string temleft(s, left, len);
                    if (hashwords.count(temleft))
                    {
                        if (hashwords[temleft] >= 0) count--;
                        hashwords[temleft]++;
                    }
                    left += len;
                }
                string temright(s, right, len);
                if (hashwords.count(temright))
                {
                    hashwords[temright]--;
                    if (hashwords[temright] >= 0) count++;
                }
                if (count == n) ret.push_back(left);
            }
        }
        return ret;
    }
};

int main()
{
    Solution s;
    vector<int> vi = s.findSubstring("aaaaaaaaaaaaaa", { "aa","aa" });
    return 0;
}